﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrnMall.Sdk.WeiXin.Domain.card
{

    /// <summary>
    /// 商户
    /// </summary>
    public class Merchant
    {
        /// <summary>
        /// 商户号id
        /// </summary>
        public string MachId { get; set; }
        /// <summary>
        /// 商户秘钥
        /// </summary>
        public string MchKey { get; set; }
        /// <summary>
        /// API V3秘钥
        /// </summary>
        public string MchKey_V3 { get; set; }
        /// <summary>
        /// API证书序列号
        /// </summary>
        public string Cert_No { get; set; }
        /// <summary>
        /// 证书路径
        /// </summary>
        public string Cert_Path { get; set; }
        /// <summary>
        /// 证书密码
        /// </summary>
        public string CertPwd { get; set; }
        /// <summary>
        /// 公众号ID
        /// </summary>
        public string AppId { get; set; }
        /// <summary>
        /// 小程序appid
        /// </summary>
        public string WeApp_AppId { get; set; }
        /// <summary>
        /// 证书加密私钥
        /// </summary>
        public string Cert_PrivateKey { get; set; }
        public Merchant() { }
        public Merchant(string machId, string cert_No)
        {
            MachId = machId;
            Cert_No = cert_No;
        }
        public Merchant(string machId, string cert_No, string appId)
        {
            MachId = machId;
            Cert_No = cert_No;
            AppId = appId;
        }
    }

    
   
    /// <summary>
    /// 代金券批次列表
    /// </summary>
    public class StockList
    {
        public int total_count { get; set; }
        public List<Stock> data { get; set; }
        public int offset { set; get; }
        public int limit { get; set; }
    }
    /// <summary>
    /// 代金券批次详情
    /// </summary>
    public class Stock
    {
        /// <summary>
        /// 批次id
        /// </summary>
        public string stock_id { get; set; }
        /// <summary>
        /// 微信为创建方商户分配的商户号
        /// </summary>
        public string stock_creator_mchid { get; set; }
        /// <summary>
        /// 批次名称
        /// </summary>
        public string stock_name { get; set; }
        /// <summary>
        /// 状态： unactivated-未激活；audit-审核中；running-运行中；stoped-已停止；paused-暂停发放
        /// </summary>
        public string status { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public string create_time { get; set; }
        /// <summary>
        /// 描述信息
        /// </summary>
        public string description { get; set; }
        /// <summary>
        /// 普通发券批次特定信息
        /// </summary>
        public StockUseRule stock_use_rule { get; set; }
        /// <summary>
        /// 可用开始时间
        /// </summary>
        public string available_begin_time { get; set; }
        /// <summary>
        /// 可用结束时间
        /// </summary>
        public string available_end_time { get; set; }
        /// <summary>
        /// 已发券数量
        /// </summary>
        public int distributed_coupons { get; set; }
        /// <summary>
        /// 是否无资金流ture-是；false-否
        /// </summary>
        public bool no_cash { get; set; }
        /// <summary>
        /// 批次开启时间
        /// </summary>
        public string start_time { get; set; }
        /// <summary>
        /// 批次停止时间
        /// </summary>
        public string stop_time { get; set; }
        /// <summary>
        /// 单品优惠特定信息
        /// </summary>
        public CutToMessage cut_to_message { get; set; }
        /// <summary>
        /// 是否单品优惠:true-是；false-否
        /// </summary>
        public bool singleitem { get; set; }
        /// <summary>
        /// 批次类型：NORMAL-代金券批次；DISCOUNT_CUT-立减与折扣；OTHER-其他
        /// </summary>
        public string stock_type { get; set; }
    }

    public class StockUseRule
    {
        /// <summary>
        /// 最大发券数
        /// </summary>
        public int max_coupons { get; set; }
        /// <summary>
        /// 总消耗金额，单位分
        /// </summary>
        public int max_amount { get; set; }
        /// <summary>
        /// 单天最高消耗金额，单位分
        /// </summary>
        public int max_amount_by_day { get; set; }
        /// <summary>
        /// 固定面额发券批次特定信息
        /// </summary>
        public FixedNormalCoupon fixed_normal_coupon { get; set; }


        /// <summary>
        ///	单用户领券限制
        /// </summary>
        public int max_coupons_per_user { get; set; }
        /// <summary>
        /// 券类型：NORMAL-满减券；CUT_TO-减至券
        /// </summary>
        public string coupon_type { get; set; }
        /// <summary>
        /// 默认不限制，值为：	小程序支付-MICROAPP、	APP支付-APPPAY、	免密支付-PPAY、付款码支付-CARD、人脸支付-FACE、（公众号、扫码等）-OTHER
        /// </summary>
        public List<object> trade_type { get; set; }
        /// <summary>
        /// 订单优惠标记
        /// </summary>
        public List<object> goods_tag { get; set; }
        /// <summary>
        /// 可与其他券叠加使用：ture-是；false-否
        /// </summary>
        public bool combine_use { get; set; }
    }
    /// <summary>
    /// 单品优惠特定信息
    /// </summary>
    public class CutToMessage
    {
        public int single_price_max { get; set; }
        public int cut_to_price { get; set; }
    }
    /// <summary>
    /// 固定面额发券批次特定信息
    /// </summary>
    public class FixedNormalCoupon
    {
        /// <summary>
        /// 面额，单位分
        /// </summary>
        public int coupon_amount { get; set; }
        /// <summary>
        /// 使用券金额门槛，单位分
        /// </summary>
        public int transaction_minimum { get; set; }
    }

    /// <summary>
    /// 发放代金券的入参
    /// </summary>
    public class SendCouponRequest
    {
        /// <summary>
        /// 批次id
        /// </summary>
        public string stock_id { get; set; }
        /// <summary>
        /// 商户此次发放凭据号（格式：商户id+日期+流水号），商户侧需保持唯一性
        /// </summary>
        public string out_request_no { get; set; }
        /// <summary>
        /// 发券方商户分配的公众账号ID
        /// </summary>
        public string appid { get; set; }
        /// <summary>
        /// 批次创建方商户号
        /// </summary>
        public string stock_creator_mchid { get; set; }
        
        //public object coupon_value { get; set; }
        //public object coupon_minimum { get; set; }
    }

    /// <summary>
    /// 代金券列表
    /// </summary>
    public class CouponList
    {
        public int total_count { get; set; }
        public List<Coupon> data { get; set; }
        public int offset { set; get; }
        public int limit { get; set; }
    }
    /// <summary>
    /// 代金券详情
    /// </summary>
    public class Coupon
    {
        public string stock_creator_mchid { get; set; }
        public string stock_id { get; set; }
        public string coupon_id { get; set; }
        /// <summary>
        /// 单品优惠特定信息
        /// </summary>
        public SingleTypeMsg singleitem_discount_off { get; set; }
        public string coupon_name { get; set; }
        public string status { get; set; }
        public string description { get; set; }
        public string create_time { get; set; }
        public bool no_cash { get; set; }
        public string available_begin_time { get; set; }
        public string available_end_time { get; set; }
        public bool singleitem { get; set; }
        /// <summary>
        /// 普通满减券面额、门槛信息
        /// </summary>
        public FixedValueStockMsg normal_coupon_information { get; set; }
        /// <summary>
        /// 已实扣代金券信息
        /// </summary>
        public CouponConsumeInfo consume_information { get; set; }
    }
    /// <summary>
    /// 单品优惠特定信息
    /// </summary>
    public class SingleTypeMsg
    {
        public int single_price_max { get; set; }
        public int cut_to_price { get; set; }
    }
    /// <summary>
    /// 普通满减券面额、门槛信息
    /// </summary>
    public class FixedValueStockMsg
    {
        public int coupon_amount { get; set; }
        public int transaction_minimum { get; set; }
    }
    /// <summary>
    ///  已实扣代金券信息
    /// </summary>
    public class CouponConsumeInfo
    {
        public string consume_time { get; set; }
        public string consume_mchid { get; set; }
        public string transaction_id { get;set; }
        public SingleitemInfo goods_detail { get; set; }
    }
    /// <summary>
    /// 商户下单单品信息
    /// </summary>
    public class SingleitemInfo
    {
        public string goods_id { get; set; }
        public int quantity { get; set; }
        public int price { get; set; }
        public int discount_amount { get; set; }
    }

    /// <summary>
    /// 通知内容
    /// </summary>
    public class NotifyInfo
    {
        /// <summary>
        /// 通知的唯一ID
        /// </summary>
        public string id { get; set; }
        /// <summary>
        /// 通知创建的时间，格式为yyyyMMddHHmmss
        /// </summary>
        public string create_time { get; set; }
        /// <summary>
        /// 通知的类型，支付成功通知的类型为TRANSACTION.SUCCESS
        /// </summary>
        public string event_type { get; set; }
        /// <summary>
        /// 通知的资源数据类型，支付成功通知为encrypt-resource
        /// </summary>
        public string resource_type { get; set; }
        /// <summary>
        /// 回调摘要
        /// </summary>
        public string summary { get; set; }

        public Resource resource { get; set; }
    }

    /// <summary>
    /// 通知数据
    /// </summary>
    public class Resource
    {
        /// <summary>
        /// 加密算法类型，目前只支持AEAD_AES_256_GCM
        /// </summary>
        public string algorithm { get; set; }
        /// <summary>
        /// 数据密文，Base64编码格式
        /// </summary>
        public string ciphertext { get; set; }
        /// <summary>
        /// 附加数据
        /// </summary>
        public string associated_data { get; set; }
        /// <summary>
        /// 随机串
        /// </summary>
        public string nonce { get; set; }
        /// <summary>
        /// 原始回调类型
        /// </summary>
        public string original_type { get; set; }
    }
    /// <summary>
    /// Resource.ciphertext 的解密后内容
    /// </summary>
    public class CipherText : Coupon
    {
        /// <summary>
        /// 减至优惠限定字段，仅减至优惠场景有返回
        /// </summary>
        public SingleTypeMsg discount_to { get; set; }
    }
}
